<template>
  <div class="ad-item">
    <div class="label">{{$attrs.label}}</div>
    <div class="value">{{itemValue}}</div>
  </div>
</template>

<script>
import { parseStatus } from '@/utils/code'
import { findDict } from '@/utils/dict'

export default {
  data() {
    return {
      dict: null
    }
  },
  computed: {
    hasDict() {
      return this.$attrs.hasOwnProperty('dictName')
    },
    hasValue() {
      return !!this.$attrs.value
    },
    itemValue() {
      if (this.hasValue) {
        if (this.hasDict) {
          return parseStatus(this.dict, this.$attrs.dictName, this.$attrs.value)
        } else {
          return this.$attrs.value
        }
      } else {
        return '-'
      }
    }
  },
  created() {
    if (this.hasDict) {
      this.dict = findDict(this)
    }
  }
}
</script>

<style lang="scss" scoped>
.ad-item { display: flex;
  .label { color: #9a9a9a; }}
</style>